
extension ListExtend<T> on List<T> {

  List<T> splitJoin(T splitItem,{bool condition=true}){
    if (!condition){
      return this;
    }
    if (length  <= 1){
      return this;
    }
    List<T> result = [];
    for (var i=0;i<length-1;i++){
      result.add(this[i]);
      result.add(splitItem);
    }
    result.add(this[length-1]);
    return result;
  }


  List<T> addPlus(T data){
    add(data);
    return this;
  }

  /// 切片
  List<T> slice({int start=0, int? end}){
    end = end ?? length;
    if(end < 0 ) {
      end = length + end;
    }
    if(end > length){
      end = length;
    }
    return sublist(start, end);
  }

  List<T> distinct<V>({V Function(T item)? func}){
    if(func==null){
      return toSet().toList();
    }
    Set<V> res = {};
    List<T> result = [];
    for (var value in this) {
        var v = func.call(value);
        if (res.contains(v)) {
          continue;
        }
        result.add(value);
        res.add(v);
    }
    return result;
  }

}

extension IterableExtend<T> on Iterable<T>{

  Iterable<T> splitJoin(T splitItem,{bool condition=true}){
    if (!condition){
      return this;
    }
    if (length  <= 1){
      return this;
    }
    var list = toList();
    List<T> result = [];
    for (var i=0;i<length-1;i++){
      result.add(list[i]);
      result.add(splitItem);
    }
    result.add(list[length-1]);
    return result;
  }

}